<template>
	<div class="content">
		<div class="clear">
			<Form inline class="fl">
				<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd" @on-change="getTime" v-model="getDate">
				</DatePicker>
				<Button class="m-r10" v-on:click="getTimeGcollect(1)">今日</Button>
				<Button class="m-r10" v-on:click="getTimeGcollect(2)">近7天</Button>
				<Button class="m-r10" v-on:click="getTimeGcollect(3)">近30天</Button>
				<Button type="primary" v-on:click="getCollectListQuery">查询</Button>
			</Form>
		</div>
		<fieldset>
			<legend>汇总</legend>
			<div>
				<tbody>
					<tr>
						<td>今日新增用户:
							<span class="blue">{{ list.newUserToday == null ? 0 : list.newUserToday }}</span>
						</td>
						<td>总用户:
							<span class="blue">{{ list.totalUser == null ? 0 : list.totalUser }}</span>
						</td>
						<td>累计交易订单:
							<span class="blue">{{ list.tradingOrder == null ? 0 : Fixed(list.tradingOrder) }}</span>
						</td>
						<td>累计OTC交易订单:
							<span class="blue">{{ list.otcTradingOrder == null ? 0 : Fixed(list.otcTradingOrder) }}</span>
						</td>
						<td>累计糖果赠送:
							<span class="blue">{{ list.sumCandy == null ? 0 : Fixed(list.sumCandy) }}</span>
						</td>
						<td>累计糖果释放:
							<span class="blue">{{ list.releaseCandy == null ? 0 : Fixed(list.releaseCandy) }}</span>
						</td>
						<td>累计充值:
							<span class="blue">{{ list.sumRecharge == null ? 0 : Fixed(list.sumRecharge) }}</span>
						</td>
						<td>累计到账:
							<span class="blue">{{ list.accumulatedAccrual == null ? 0 : Fixed(list.accumulatedAccrual) }}</span>
						</td>
						<td>累计提现:
							<span class="blue">{{ list.accumulatedWithdrawal == null ? 0 : Fixed(list.accumulatedWithdrawal) }}</span>
						</td>
						<td>累计推广收益:
							<span class="blue">{{ list.promotionBenefits == null ? 0 : Fixed(list.promotionBenefits) }}</span>
						</td>
					</tr>
					<tr>
						<td>累计交易买入手续费:
							<span class="blue">{{ list.purchaseCharges == null ? 0 : Fixed(list.purchaseCharges) }}</span>
						</td>
						<td>累计交易卖出手续费:
							<span class="blue">{{ list.sellingCharges == null ? 0 : Fixed(list.sellingCharges) }}</span>
						</td>
					</tr>
				</tbody>
			</div>
		</fieldset>
		<fieldset>
			<legend>时间段汇总(<span v-text="day" id="today"></span>)</legend>
			<div>
				<table>
					<tbody>
						<tr>

							<td>累计交易订单:
								<span class="blue">{{ timeGcollect.tradingOrder == null ? 0 : Fixed(timeGcollect.tradingOrder) }}</span>
							</td>
							<td>累计OTC交易订单:
								<span class="blue">{{ timeGcollect.otcTradingOrder == null ? 0 : Fixed(timeGcollect.otcTradingOrder) }}</span>
							</td>
							<td>累计糖果赠送:
								<span class="blue">{{ timeGcollect.sumCandy == null ? 0 : Fixed(timeGcollect.sumCandy) }}</span>
							</td>
							<td>累计糖果释放:
								<span class="blue">{{ timeGcollect.releaseCandy == null ? 0 : Fixed(timeGcollect.releaseCandy) }}</span>
							</td>
							<td>累计充值:
								<span class="blue">{{ timeGcollect.sumRecharge == null ? 0 : Fixed(timeGcollect.sumRecharge) }}</span>
							</td>
							<td>累计到账:
								<span class="blue">{{ timeGcollect.accumulatedAccrual == null ? 0 : Fixed(timeGcollect.accumulatedAccrual) }}</span>
							</td>
							<td>累计提现:
								<span class="blue">{{ timeGcollect.accumulatedWithdrawal == null ? 0 : Fixed(timeGcollect.accumulatedWithdrawal) }}</span>
							</td>
							<td>累计推广收益:
								<span class="blue">{{ timeGcollect.promotionBenefits == null ? 0 : Fixed(timeGcollect.promotionBenefits) }}</span>
							</td>
							<td>累计交易买入手续费:
								<span class="blue">{{ timeGcollect.purchaseCharges == null ? 0 : Fixed(timeGcollect.purchaseCharges) }}</span>
							</td>
							<td>累计交易卖出手续费:
								<span class="blue">{{ timeGcollect.sellingCharges == null ? 0 : Fixed(timeGcollect.sellingCharges) }}</span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</fieldset>
		<Button class="daochu" type="primary" size="large" @click="exportData" :loading="dcShow">
            <Icon type="ios-download-outline"></Icon> 导出</Button>
		<Table stripe :columns="columns" :data='collectList' ref="table" :loading="loading"></Table>
		<Page :total="info" :page-size="pageSize" show-elevator show-total @on-change="cuctGetCollectList" :current.sync="page"></Page>
	</div>
</template>
<script>
	export default {
		data() {
			return {
				dcShow: false,
				loading: true,
				day: '', // 时间显示(今日,近7天,近30天)
				list: [], // 财务汇总统计
				timeGcollect: [], // 时间段汇总
				collectList: [], // 财务统计列表的数据
				dataValue: ['',''], // 时间段值
				info: null, // 总条数
				page: 1, // 页数
				pageSize: 20, // 每页多少条
				getDate: '',
				current: 1,
				downList: [],
				jsonData: [],
				columns: [{
						title: '日期',
						key: 'times',
						align: 'center',
						sortable: true,
						fixed: 'left',
						render: (h, params) => {
							return h('div', params.row.times == null ? '#' : params.row.times)
						}
					},
					{
						title: '累计交易订单',
						align: 'center',
						key: 'tradingOrder',
						render: (h, params) => {
							return h('div', params.row.tradingOrder == null ? '#' : this.Fixed(params.row.tradingOrder))
						}
					},
					{
						title: '累计OTC交易订单',
						align: 'center',
						key: 'otcTradingOrder',
						render: (h, params) => {
							return h('div', params.row.otcTradingOrder == null ? '#' : this.Fixed(params.row.otcTradingOrder))
						}
					},
					{
						title: '累计糖果赠送',
						align: 'center',
						key: 'sumCandy',
						render: (h, params) => {
							return h('div', params.row.sumCandy == null ? '#' : this.Fixed(params.row.sumCandy))
						}
					},
					{
						title: '累计糖果释放',
						align: 'center',
						key: 'releaseCandy',
						render: (h, params) => {
							return h('div', params.row.releaseCandy == null ? '#' : this.Fixed(params.row.releaseCandy))
						}
					},
					{
						title: '累计充值',
						align: 'center',
						key: 'sumRecharge',
						render: (h, params) => {
							return h('div', params.row.sumRecharge == null ? '#' : this.Fixed(params.row.sumRecharge))
						}
					},
					{
						title: '累计到账',
						align: 'center',
						key: 'accumulatedAccrual',
						render: (h, params) => {
							return h('div', params.row.accumulatedAccrual == null ? '#' : this.Fixed(params.row.accumulatedAccrual))
						}
					},
					{
						title: '累计提现',
						align: 'center',
						key: 'accumulatedWithdrawal',
						render: (h, params) => {
							return h('div', params.row.accumulatedWithdrawal == null ? '#' : this.Fixed(params.row.accumulatedWithdrawal))
						}
					},
					{
						title: '累计推广收益',
						align: 'center',
						key: 'promotionBenefits',
						render: (h, params) => {
							return h('div', params.row.promotionBenefits == null ? '#' : this.Fixed(params.row.promotionBenefits))
						}
					},
					{
						title: '累计交易买入手续费',
						align: 'center',
						key: 'purchaseCharges',
						render: (h, params) => {
							return h('div', params.row.purchaseCharges == null ? '#' : this.Fixed(params.row.purchaseCharges))
						}
					},
					{
						title: '累计交易卖出手续费',
						align: 'center',
						key: 'sellingCharges',
						render: (h, params) => {
							return h('div', params.row.sellingCharges == null ? '#' : this.Fixed(params.row.sellingCharges))
						}
					},
				]
			}
		},
		created() {

		},
		mounted() {
			this.$Message.config({
				top: 250
			});
			this.$nextTick(() => {
				this.getGcollect(); // 财务汇总统计查询
				this.getCollectList(); // 财务统计列表查询

				document.getElementById('today').innerHTML = '今日';
				let token = localStorage.getItem('mytoken');
				let params = this.qs.stringify({
					typeId: 1,
				})
				this.axios.post('/admin/accounting/statistical/time', params).then(res => {
					if(res.data.code == 200) {
						this.timeGcollect = res.data.data;
					}
				})
			})
		},
		methods: {
			exportData() {
				this.jsonData = [];
				this.dcShow = true;
				this.axios.post('/admin/accounting/statistical/list', this.qs.stringify({
					current: this.page,
					size: this.pageSize,
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})).then(res => {
					if(res.data.code == 200) {
						this.axios.post('/admin/accounting/statistical/list', this.qs.stringify({
							current: 1,
							size: res.data.data.total,
							startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
							endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
						})).then(res => {
							if(res.data.code == 200) {
								this.downList = res.data.data.records;
								this.downList.forEach((row, index) => {
									this.downList[index].times = this.downList[index].times == null ? '#' : this.Fixed(this.downList[index].times);
									this.downList[index].tradingOrder = this.downList[index].tradingOrder == null ? '#' : this.Fixed(this.downList[index].tradingOrder);
									this.downList[index].otcTradingOrder = this.downList[index].otcTradingOrder == null ? '#' : this.Fixed(this.downList[index].otcTradingOrder);
									this.downList[index].sumCandy = this.downList[index].sumCandy == null ? '#' : this.Fixed(this.downList[index].sumCandy);
									this.downList[index].releaseCandy = this.downList[index].releaseCandy == null ? '#' : this.Fixed(this.downList[index].releaseCandy);
									this.downList[index].sumRecharge = this.downList[index].sumRecharge == null ? '#' : this.Fixed(this.downList[index].sumRecharge);
									this.downList[index].accumulatedAccrual = this.downList[index].accumulatedAccrual == null ? '#' : this.Fixed(this.downList[index].accumulatedAccrual);
									this.downList[index].accumulatedWithdrawal = this.downList[index].accumulatedWithdrawal == null ? '#' : this.Fixed(this.downList[index].accumulatedWithdrawal);
									this.downList[index].promotionBenefits = this.downList[index].promotionBenefits == null ? '#' : this.Fixed(this.downList[index].promotionBenefits);
									this.downList[index].purchaseCharges = this.downList[index].purchaseCharges == null ? '#' : this.Fixed(this.downList[index].purchaseCharges);
									this.downList[index].sellingCharges = this.downList[index].sellingCharges == null ? '#' : this.Fixed(this.downList[index].sellingCharges);

									this.jsonData.push({
										times: this.downList[index].times,
										tradingOrder: this.downList[index].tradingOrder,
										otcTradingOrder: this.downList[index].otcTradingOrder,
										sumCandy: this.downList[index].sumCandy,
										releaseCandy: this.downList[index].releaseCandy,
										sumRecharge: this.downList[index].sumRecharge,
										accumulatedAccrual: this.downList[index].accumulatedAccrual,
										accumulatedWithdrawal: this.downList[index].accumulatedWithdrawal,
										promotionBenefits: this.downList[index].promotionBenefits,
										purchaseCharges: this.downList[index].purchaseCharges,
										sellingCharges: this.downList[index].sellingCharges,
									})
								})
								let str = `日期,今日交易订单,今日OTC交易订单,累计糖果赠送,累计糖果释放,累计充值,累计到账,累计提现,累计推广收益,累计交易买入手续费,累计交易卖出手续费\n`;
								this.downLoad(this.jsonData, str, '财务统计');
							}
						})
					}
				})
			},
			// 处理时间段时间格式
			getTime(daterange) {
				this.dataValue = daterange
			},
			getCollectList() { // 财务统计列表查询
				let token = localStorage.getItem("mytoken");
				let param = this.qs.stringify({
					current: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})
				this.axios.post('/admin/accounting/statistical/list', param).then(res => {
					if(res.data.code == 200) {
						this.collectList = res.data.data.records;
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
			cuctGetCollectList(page) { // 财务统计列表分页查询
				this.loading = true;
				let token = localStorage.getItem("mytoken");
				let params;

				if(this.dataValue.length > 0) {
					params = this.qs.stringify({
						current: page, // 当前页【可选，默认1】
						size: this.pageSize, // 每页记录数【可选，默认20】
						startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
						endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
					})
				} else {
					params = this.qs.stringify({
						current: page, // 当前页【可选，默认1】
						size: this.pageSize, // 每页记录数【可选，默认20】
						typeId: this.day == '今日' ? 1 : this.day == '近7天' ? 2 : this.day == '近30天' ? 3 : 0
					})
				}

				this.axios.post('/admin/accounting/statistical/list', params).then(res => {
					if(res.data.code == 200) {
						this.collectList = res.data.data.records;
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
			getCollectListQuery() { // 财务统计列表条件查询
				this.loading = true;
				let token = localStorage.getItem("mytoken");
				let params = this.qs.stringify({
					current: 1, // 当前页【可选，默认1】
					size: this.pageSize,
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})
				this.axios.post('/admin/accounting/statistical/list', params).then(res => {
					if(res.data.code == 200) {
						this.page = 1;
						this.collectList = res.data.data.records;
						this.info = res.data.data.total;
						this.day = this.dataValue.length <= 0 ? '2000-12-30 - 2200-12-30' : this.dataValue[0].replace(' 00:00:00', '') + ' - ' + this.dataValue[1].replace(' 00:00:00', '');
						this.loading = false;
					}
				})

				let params2 = this.qs.stringify({
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})
				this.axios.post('/admin/accounting/statistical/time', params2).then(res => {
					if(res.data.code == 200) {
						this.timeGcollect = res.data.data;
					}
				})
			},
			getGcollect() { // 	财务统计汇总
				this.axios.get('/admin/accounting/statistical').then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data;
					}
				})
			},
			getTimeGcollect(index) { // 时间段汇总
				this.getDate = '';
				if(index == 1) {
					this.day = '今日';
				}
				if(index == 2) {
					this.day = '近7天';
				}
				if(index == 3) {
					this.day = '近30天';
				}
				let token = localStorage.getItem('mytoken');
				let params = this.qs.stringify({
					typeId: index,
				})
				this.current = 1;
				this.axios.post('/admin/accounting/statistical/time', params).then(res => {
					if(res.data.code == 200) {
						this.timeGcollect = res.data.data;
					}
				})

				this.loading = true;
				let params2 = this.qs.stringify({
					current: 1, // 当前页【可选，默认1】
					size: this.pageSize,
					typeId: index,
				})
				this.axios.post('/admin/accounting/statistical/list', params2).then(res => {
					if(res.data.code == 200) {
						this.collectList = res.data.data.records;
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
		}
	}
</script>